// Vanity overriding wisdom.

#include <bits/stdc++.h>

using ll = long long;
inline ll sum_1(ll a, ll b) { return (b - a + 1) * (a + b) / 2; }

namespace FastIO {
	template <typename T> inline T read() { T x = 0, w = 0; char ch = getchar(); while (ch < '0' || ch > '9') w |= (ch == '-'), ch = getchar(); while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return w ? -x : x; }
	template <typename T> inline void write(T x) { if (x == 0) return; write<T>(x / 10), putchar(x % 10 + '0'); }
	template <typename T> inline void print(T x) { if (x < 0) putchar('-'), x = -x; if (x == 0) putchar('0'); write<T>(x); }
	template <typename T> inline void print(T x, char ed) { print<T>(x), putchar(ed); }
	inline char rChar() { char ch = getchar(); while (!isdigit(ch)) ch = getchar(); return ch; }
}; using namespace FastIO;

#define MAXN 200001
int a[MAXN], A[MAXN], b[MAXN], c[MAXN]; ll ans[MAXN];

const int L = 17;
std::vector<int> d[L + 1];
std::vector<int> win[L + 1];

void recalc(int id, int dep) {
	int v = id; --id;
	for (int i = 1, st; i <= dep; ++i) {
		st = (id & 1), id >>= 1;
		if (d[i][id] == 0) {
			if ((st == 0 && a[v] >= i) || (st == 1 && a[win[i - 1][id << 1]] < i)) win[i][id] = v; else v = win[i][id] = win[i - 1][id << 1 | (st ^ 1)];
		} else {
			if ((st == 1 && a[v] >= i) || (st == 0 && a[win[i - 1][id << 1 | 1]] < i)) win[i][id] = v; else v = win[i][id] = win[i - 1][id << 1 | (st ^ 1)];
		}
	}
}

void solve(int k) {
	int n = 1 << k;
//	for (int i = 0, b = 1 << (k - i - 1); i < k; ++i, b >>= 1) 
//		for (int w = 0; w < b; ++w) win[w] = cal(get(i - 1, w << 1), get(i - 1, w << 1 | 1), d[i][w], i + 1);
	if (d[k][0] == 1 || a[win[k - 1][0]] >= k) win[k][0] = win[k - 1][0];
	if (d[k][0] == 0 && a[win[k - 1][0]] >= k) { for (int r = n / 2 + 1; r <= n; ++r) ans[r] = win[k][0]; return; }
	for (int pos = n / 2 + 1; pos <= n; ++pos) {
		a[pos] = A[pos], recalc(pos, k), ans[pos] = win[k][0];
		for (int cut = 1, dep = k - 1, l = n / 2 + 1, r = n, mid; l != r; --dep) {
			mid = l + r >> 1;
			if (pos <= mid) {
				if (d[dep][cut] == 1 || a[win[dep][cut]] < dep) ans[pos] += sum_1(mid + 1, r);
				r = mid, cut <<= 1;
			} else {
				if (d[dep][cut] == 0 && a[win[dep][cut]] >= dep) break;
				l = mid + 1, cut = cut << 1 | 1;
			}
		}
//		printf("ans[%d] = %lld\n", pos, ans[pos]);
//		if (pos > 16) continue;
//		for (int i = 0; i <= k; ++i, puts("")) for (int d = 0; d < (1 << (k - i)); ++d) print<int>(win[i][d], ' ');
//		puts("");
	}
}

int main() {
	freopen("arena.in", "r", stdin);
	freopen("arena.out", "w", stdout);
	int n = read<int>(), m = read<int>(), K = 1; ans[1] = 1;
	for (int i = 1; i <= n; ++i) b[i] = read<int>();
	for (int i = 1; i <= m; ++i) c[i] = read<int>();
	while ((1 << K) < n) ++K;
	for (int i = 0; i <= K; ++i) {
		d[i].resize(1 << (K - i)), win[i].resize(1 << (K - i));
		if (i == 0) for (int i = 0; i < (1 << K); ++i) win[0][i] = i + 1;
		else for (auto &&j : d[i]) j = rChar() - '0';
	}
	int t = read<int>();
	while (t--) {
		int x[4];
		for (auto &&u : x) u = read<int>();
		for (int i = 1; i <= n; ++i) A[i] = (b[i] ^ x[i & 3]);
		for (int i = 1; i <= K; ++i) for (auto &&u : win[i]) u = 0;
		a[1] = 1;
//		for (int i = 1; i <= 16; ++i) print<int>(A[i], " \n"[i == 16]);
		for (int k = 1; k <= K; ++k) solve(k);
		ll res = 0;
		for (int i = 1; i <= m; ++i) res ^= (1ll * i * ans[c[i]]);
		print<ll>(res, '\n');
	}
	return 0;
}
